<!doctype html>
<html lang="zh-Hans">
	<head>
		<title>PCB铜箔载流计算器 - 嵌入式工具集</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<!-- 引入Tailwind CSS -->
		<script src="https://cdn.tailwindcss.com"></script>
		<!-- 以下为浏览器中的配置，正式 编译之后请注释掉这段-->
		<link rel="stylesheet" href="../styles/styles.css">
		<!-- 以下为LCEDA中的配置，正式 编译之后请勿注释这段-->
		<link rel="stylesheet" href="/iframe/styles/styles.css">
		<style>
			/* 内联图标样式 - 不依赖外部字体文件 */
			.fa {
				display: inline-block;
				width: 1em;
				height: 1em;
				font-size: inherit;
				line-height: 1;
				vertical-align: middle;
				text-align: center;
			}

			.fa-calculator::before {
				content: '📟';
				font-size: 1.2em;
			}

			.fa-refresh::before {
				content: '↺';
				font-size: 1.2em;
			}

			/* 确保在插件环境中的兼容性 */
			body {
				margin: 0;
				padding: 0;
				font-size: 16px;
			}

			/* 确保容器在不同环境中自适应 */
			div.max-w-md {
				max-width: 100% !important;
				width: 100%;
				box-sizing: border-box;
			}
		</style>
		<!-- 引入共享环境判断工具 -->
		<script src="../utils/environment.js"></script>
	<body class="bg-gradient-to-br from-light to-blue-50 min-h-screen p-4 md:p-6 font-sans">
		<div class="max-w-md mx-auto">
			<h2 class="text-xl md:text-2xl font-bold text-primary mb-6 text-center">PCB铜皮载流计算器</h2>

			<div class="formula-box mb-6 p-4 bg-light rounded-lg border border-gray-200">
				<p><strong>铜皮载流估算公式</strong></p>
				<p class="text-sm mt-1">基于IPC-2221标准的简化计算</p>
				<div class="mt-3 bg-gray-50 p-3 rounded">
					<p class="text-center font-mono"><strong>I = k × A^0.725 × ΔT^0.44</strong></p>
					<p class="text-xs mt-2 text-gray-600 text-left">
						其中：I = 载流量 (A)<br>
						k = 常数 (外层铜皮: 0.048)<br>
						A = 铜皮截面积 (mm²)<br>
						ΔT = 温度上升 (°C)<br>
						A = 宽度(mm) × 厚度(mm)，1oz铜厚 = 0.035mm
					</p>
				</div>
			</div>

			<div class="space-y-5">
				<div>
					<label for="current-thickness" class="block text-sm font-medium text-gray-700 mb-1">铜皮厚度 (oz)</label>
					<select id="current-thickness" class="form-input">
						<option value="0.5">0.5 oz (17.5 μm)</option>
						<option value="1" selected>1 oz (35 μm)</option>
						<option value="2">2 oz (70 μm)</option>
						<option value="3">3 oz (105 μm)</option>
					</select>
				</div>

				<div>
					<label for="current-width" class="block text-sm font-medium text-gray-700 mb-1">铜皮宽度 (mm)</label>
					<input type="number" id="current-width" class="form-input" placeholder="请输入铜皮宽度" value="1" min="0.1" step="0.1" />
				</div>

				<div>
					<label for="current-length" class="block text-sm font-medium text-gray-700 mb-1">铜皮长度 (mm)</label>
					<input type="number" id="current-length" class="form-input" placeholder="请输入铜皮长度" value="100" min="1" step="1" />
				</div>

				<div>
					<label for="current-temp-rise" class="block text-sm font-medium text-gray-700 mb-1">温度上升 (°C)</label>
					<select id="current-temp-rise" class="form-input">
						<option value="10">10°C</option>
						<option value="15">15°C</option>
						<option value="20">20°C</option>
						<option value="30">30°C</option>
						<option value="40">40°C</option>
						<option value="50" selected>50°C</option>
					</select>
				</div>

				<div class="flex space-x-3">
					<button onclick="pcbCopperCalculate()" class="btn-primary flex-1"><i class="fa fa-calculator mr-2"></i>计算</button>
					<button onclick="pcbCopperClear()" class="btn-secondary"><i class="fa fa-refresh mr-1"></i></button>
				</div>

				<div id="pcb-copper-results" class="space-y-4 mt-6">
					<div class="p-4 bg-light rounded-lg">
						<h3 class="font-bold text-gray-700 mb-3">计算结果</h3>
						<div class="space-y-2">
							<div class="flex justify-between">
								<span class="text-sm text-gray-600">最大载流量：</span>
								<span class="font-medium text-primary" id="result-current">0 A</span>
							</div>
							<div class="flex justify-between">
								<span class="text-sm text-gray-600">铜皮电阻：</span>
								<span class="font-medium text-primary" id="result-resistance">0 Ω</span>
							</div>
							<div class="flex justify-between">
								<span class="text-sm text-gray-600">铜皮截面积：</span>
								<span class="font-medium text-primary" id="result-area">0 mm²</span>
							</div>
							<div class="flex justify-between">
								<span class="text-sm text-gray-600">铜皮体积：</span>
								<span class="font-medium text-primary" id="result-volume">0 mm³</span>
							</div>
						</div>
					</div>

					<div class="text-sm text-gray-500 p-3 bg-blue-50 rounded-lg">
						<p><i class="fa fa-info-circle text-blue-500 mr-2"></i>注：计算结果基于IPC-2221标准的简化公式，仅供参考。实际应用中应考虑环境温度、PCB层数、散热条件等因素。</p>
					</div>
				</div>
			</div>
		</div>

		<script>
			// PCB铜皮载流计算
			function pcbCopperCalculate() {
				// 获取输入值
				const thickness = parseFloat(document.getElementById('current-thickness').value);
				const width = parseFloat(document.getElementById('current-width').value);
				const length = parseFloat(document.getElementById('current-length').value);
				const tempRise = parseFloat(document.getElementById('current-temp-rise').value);

				// 验证输入
				if (isNaN(thickness) || isNaN(width) || isNaN(length) || isNaN(tempRise)) {
					return;
				}

				if (width <= 0 || length <= 0) {
					return;
				}

				// 计算截面积（mm²）
				// 1 oz铜厚 = 35 μm = 0.035 mm
				const thicknessMM = thickness * 0.035;
				const area = width * thicknessMM;

				// 计算体积（mm³）
				const volume = area * length;

				// 使用IPC-2221简化公式计算载流量
				// I = k * A^0.725 * ΔT^0.44
				// 其中k为常数，ΔT为温度上升
				let k = 0.048; // 内部层铜皮
				// 对于外层铜皮，k值稍大
				// 这里使用简化值，取0.048（保守估计）

				const current = k * Math.pow(area, 0.725) * Math.pow(tempRise, 0.44);

				// 计算铜皮电阻（Ω）
				// 铜的电阻率：1.7241e-8 Ω·m = 1.7241e-5 Ω·mm
				const resistivity = 1.7241e-5; // Ω·mm
				const resistance = (resistivity * length) / area;

				// 更新显示
				document.getElementById('result-current').textContent = current.toFixed(3) + ' A';
				document.getElementById('result-resistance').textContent = formatSmallNumber(resistance) + ' Ω';
				document.getElementById('result-area').textContent = area.toFixed(4) + ' mm²';
				document.getElementById('result-volume').textContent = volume.toFixed(2) + ' mm³';
			}

			// 格式化小数值
			function formatSmallNumber(num) {
				if (Math.abs(num) < 0.001) {
					return num.toExponential(3);
				} else {
					return num.toFixed(6).replace(/\.?0+$/, '');
				}
			}

			// 清空输入和结果
			function pcbCopperClear() {
				document.getElementById('current-thickness').value = '1';
				document.getElementById('current-width').value = '1';
				document.getElementById('current-length').value = '100';
				document.getElementById('current-temp-rise').value = '50';
				pcbCopperCalculate();
			}

			// 页面加载时初始化计算
			document.addEventListener('DOMContentLoaded', function () {
				pcbCopperCalculate();
			});

			// 暴露给父页面的接口
			window.pcbCopperCalculate = pcbCopperCalculate;
			window.pcbCopperClear = pcbCopperClear;
		</script>
		
		<!-- 页脚 -->
		<footer class="max-w-md mx-auto mt-8 text-center text-sm text-gray-500">
			<p>版本号: V0.0.1-20251004</p>
		</footer>
	</body>
</html>